package NG::Gen::AuthCgi;
use strict;
use warnings;
use utf8;

use base 'NG::Sys::Loop::Cgi';

sub on_init_process {
	my ($app) = @_;
	my ($form) = $app->SUPER::on_init_process;
	if((my $ses = $form->cookie("session")) && (my $id = $form->cookie("id"))){
		my $user = $app->users->get_by_id($id);
		if($user->check_session($ses)){
			$form->{user} = $user;
			if($form->{input}{vk} && $form->{input}{vk} == $user->vk){
				$form->{user_is_valid} = 1;
			}
		}
	}
	return ($form);
}


1;
